<!DOCTYPE html>
<html lang="zh-cn">

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<title>报表中心</title>
		<!--<link rel='Shortcut Icon' type='image/x-icon' href='../assets/img/firstpage/时时业绩跟踪.png'>-->
		<link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui-for-work.min.css" />

		<script type="text/javascript" src="./js/jquery-2.2.4.min.js"></script>
		<link href="./css/animate.css" rel="stylesheet">
		<script type="text/javascript" src="./component/layer-v3.0.3/layer/layer.js"></script>
		<link rel="stylesheet" href="./component/font-awesome-4.7.0/css/font-awesome.min.css">
		<script src="../assets/js/m.js"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
		<!--<script src="//cdn.bootcss.com/eruda/1.4.2/eruda.min.js"></script>
		<script>
			eruda.init();
		</script>-->
		<style type="text/css">
			body {
				background-color: rgba(242, 242, 242, 1);
			}
			
			.text14 {
				font-size: 14px;
			}
			
			.text12 {
				font-size: 12px;
			}
			
			.user {
				margin: 9px 0;
			}
			
			.margintop5 {
				margin-top: 4px !important;
			}
			
			.nine-content {
				padding: 5px;
			}
			
			.bgwhite {
				background-color: white;
				-webkit-touch-callout: none;
				-webkit-user-select: none;
				-khtml-user-select: none;
				-moz-user-select: none;
				-ms-user-select: none;
				user-select: none;
			}
			
			.weui-grid__icon img,
			.weui-grid__icon {
				width: 50px;
				height: 50px;
			}
			/**/
			
			.weui-grid {
				padding: 10px 10px 0 10px;
			}
			
			.weui-grid__label {
				height: 40px;
				word-wrap: break-word;
				word-break: normal;
				white-space: inherit;
			}
			
			[v-cloak] {
				display: none;
			}
		</style>
	</head>

	<body>
		<div id="app" v-cloak>
			<div class="weui-cells" style="margin-top: 0;">
				<div class="weui-cell">
					<div class="weui-cell__bd">
						<div class="user text14">当前登录：{{userName}}</div>
					</div>
					<div class="weui-cell__ft">
						<div id="tp-weather-widget"></div>
					</div>
				</div>
			</div>
			<div class="nine-content weui-flex">
				<div class="weui-flex__item">
					<div class="weui-grids">
						<a :href="itemLink(item)" class="weui-grid bgwhite" v-for="item in pageData" :id="item.Id">
							<!--<a :href="itemLink(item)" class="weui-grid bgwhite" v-for="item in testitems" :id="item.Id">-->
							<div class="weui-grid__icon" :style="backgroundimg(item)">
							</div>
							<p class="weui-grid__label text12">
								{{item.Title}}
							</p>
						</a>
					</div>
				</div>
			</div>
			<div id="loadingToast" v-show="loading">
				<div class="weui-mask_transparent"></div>
				<div class="weui-toast">
					<i class="weui-loading weui-icon_toast"></i>
					<p class="weui-toast__content">数据加载中</p>
				</div>
			</div>
		</div>
		<script>
			(function(T, h, i, n, k, P, a, g, e) {
				g = function() {
					P = h.createElement(i);
					a = h.getElementsByTagName(i)[0];
					P.src = k;
					P.charset = "utf-8";
					P.async = 1;
					a.parentNode.insertBefore(P, a)
				};
				T["ThinkPageWeatherWidgetObject"] = n;
				T[n] || (T[n] = function() {
					(T[n].q = T[n].q || []).push(arguments)
				});
				T[n].l = +new Date();
				if(T.attachEvent) {
					T.attachEvent("onload", g)
				} else {
					T.addEventListener("load", g, false)
				}
			}(window, document, "script", "tpwidget", "//widget.seniverse.com/widget/chameleon.js"))
		</script>
		<script>
			tpwidget("init", {
				"flavor": "slim",
				"location": "WX4FBXXFKE4F",
				"geolocation": "enabled",
				"language": "zh-chs",
				"unit": "c",
				"theme": "chameleon",
				"container": "tp-weather-widget",
				"bubble": "enabled",
				"alarmType": "badge",
				"uid": "UC5D2D692B",
				"hash": "ecf791d9c6b28930d6b7503d59d09aed"
			});
			tpwidget("show");
		</script>
	</body>
	<script type="text/javascript">
		var my = null;
		new Vue({
			el: '#app',
			data: {
				testitems: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
				msg: 'hello Vue',
				show: false,
				code: '',
				config: '',
				pageData: '',
				userName: '',
				url3: '',
				weather: false,
				loading: false
			},
			mounted() {
				window.addEventListener('contextmenu', function(e) {
					e.preventDefault();
				});
				var saveCode = localStorage.getItem('code')
				my = this;
				this.url3 = window.location.href;
				this.code = this.getUrlParam("code");
				this.config = this.getUrlParam("state");
				new window.Kmer({
					"AppRootPath": "",
					"CurrentUrl": ""
				});
				if(saveCode && my.code == saveCode) {
					//这是返回获取缓存数据
					try {
						my.pageData = JSON.parse(localStorage.getItem("pageData"));
						if(my.pageData[0].UserName) {
							my.userName = my.pageData[0].UserName;
						}
						return false;
					} catch(e) {
						//TODO handle the exception
					}
				}
				localStorage.setItem('code', my.code);
				this.GetDepartmentByCode();
				this.GetConfig();
				setTimeout(() => {
					my.weather = true;
				}, 1500)
			},
			methods: {
				GetConfig() {
					Y.API2("WXBase",
						"GetConfig", {
							"url": my.url3,
							"wxConfig": my.config
						},
						function(data) {

							if(data.Success == false) {
								console.log(data.Message);
							} else {
								wx.config({
									//beta: true,// 必须这么写，否则wx.invoke调用形式的jsapi会有问题
									debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
									appId: data.corpId, // 必填，企业微信的corpID
									timestamp: data.timeStamp, // 必填，生成签名的时间戳
									nonceStr: data.nonceStr, // 必填，生成签名的随机串
									signature: data.signature, // 必填，签名，见附录1
									jsApiList: [
										"onMenuShareWechat", "onMenuShareAppMessage", "hideOptionMenu"
									]
									// 必填，需要使用的JS接口列表，所有JS接口列表见附录2
								});
							}
						});
					wx.ready(function() {
						/* begin禁用微信分享功能 */
						function onBridgeReady() {
							WeixinJSBridge.call('hideOptionMenu');
						}

						if(typeof WeixinJSBridge == "undefined") {
							if(document.addEventListener) {
								document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
							} else if(document.attachEvent) {
								document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
								document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
							}
						} else {
							onBridgeReady();
						}
						/* end禁用微信分享功能 */
					});
				},
				itemLink(item) {
					try {
						let parmaUrl = `${item.Link}&UserName=${item.UserName}&UserID=${item.UserId}&Title=${item.Title}&Id=${item.Id}&Config=${my.config}`;
						let hrefUrl = `CommonPage.html?realUrl=${encodeURIComponent(parmaUrl)}`;
						//						console.log(`parmaUrl:${parmaUrl}`)
						//					console.log(`hrefUrl:${hrefUrl}`)
						return hrefUrl;
					} catch(e) {
						//TODO handle the exception
					}

				},
				backgroundimg(item) {
					return `backgroundImage:url(${item.IconUrl});backgroundSize:cover;`;
				},
				GetDepartmentByCode() {
					Y.API2("WxReport", "GetReportListByCode", {
							"Code": my.code,
							"wxConfig": my.config
						},
						function(data) {
							console.log(data);
							if(data.Success == false) {
								console.log(data.Message);
							} else {
								my.pageData = data;
								localStorage.setItem("pageData", JSON.stringify(data))
								if(data[0].UserName) {
									my.userName = data[0].UserName;
								}

								let reportid = my.getUrlParam("reportid");
								//								    
								if(reportid !== null) {

									my.$nextTick(() => {
										let currentbtn = document.getElementById(reportid);
										currentbtn.click();
									})
								}

							}
						});
				},
				getUrlParam(name) {
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
					var r = window.location.search.substr(1).match(reg);
					if(r != null) return unescape(r[2]);
					return null;
				}
			}
		})
	</script>

</html>